<? include "../connect.php"; ?>
<?php
ob_start();
session_start();
date_default_timezone_set('Asia/Bangkok');
$emp_id=$_GET['emp_id'];

require('fpdf.php');
define('FPDF_FONTPATH','font/');

$test = $_GET['emp_id'];
class PDF extends FPDF{

	function conv($string){
	return iconv('UTF-8', 'TIS-620', $string);
	}

	function Header(){

			$this->AddFont('angsa','','angsa.php');
			$this->AddFont('angsana','B','angsab.php');
			$this->SetFont('angsana','B',10);
			$this->SetFont('angsa','',14);
			$this->SetLeftMargin( 20 );
			$this->Text(170,12,iconv( 'UTF-8','TIS-620',"F-IT-001  R06"),0,1,"R");
			$this->SetFillColor(194,194,194);
			$this->Ln(5);
			$this->SetFont('angsa','',14);
			$this->Cell(170,7,iconv('UTF-8','TIS-620','ใบรายชื่อเครื่องคอมพิวเตอร์'),1,1,'C',true);
			$this->Ln(2);
			$this->Cell(145,10,iconv( 'UTF-8','TIS-620',"วันที่จัดทำ............................................"));
			$this->Cell(25,10,iconv( 'UTF-8','TIS-620',"หน้า ").$this->PageNo().' /  tp' ,0,0,'R');
			$this->Ln();
			//Colors, line width and bold font
			$this->SetLineWidth(0.2);
			$this->SetFont('angsana','B',14);
			//Header
			$header=array('No.','รหัสเครื่อง','ชื่อเครื่อง','แผนก/ฝ่าย','IP No.');
			$w=array(15,35,40,40,40);
			for($i=0;$i<count($header);$i++)
				//$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
			$this->Cell($w[$i],10,iconv('UTF-8', 'TIS-620', $header[$i]),1,0,'C');
			$this->Ln();

		}
	
	function Footer(){
		
		$this->SetFont('angsa','',12);
		$this->SetY(-15);
		$this->Cell(30,0,iconv( 'UTF-8','TIS-620',"ผู้จัดทำ........................"),0,0,'L');
		$this->Cell(67,0,iconv( 'UTF-8','TIS-620',"หัวหน้าแผนกเทคโนโลยีสารสนเทศ.............................."),0,0,'L');
		$this->Cell(50,0,iconv( 'UTF-8','TIS-620',"หัวหน้าอาวุโสแผนกเทคโนโลยีสารสนเทศ.............................."),0,0,'L');
		
		}

		//Load data
	function LoadData($file)
	{
		//Read file lines
		$lines=file($file);
		$data=array();
		foreach($lines as $line)
			$data[]=explode(';',chop($line));
		return $data;
	}

	//Colored table
	function FancyTable($header,$data)
	{
		$w=array(15,35,40,40,40);
		$this->SetLineWidth(0.2);
		//Color and font restoration
		$this->SetFillColor(255,255,255);
		$this->SetTextColor(0);
		$this->SetFont('angsa','',12);
		//Data
		$fill=false;
		$i=1;
		$sum=0;
		foreach($data as $row)
		
		{
			$this->Cell($w[0],7,$i,1,0,'C',$fill);
			$this->Cell($w[1],7,$row['pd_name'],1,0,'L',$fill);
			$this->Cell($w[2],7,$row['cn_comeName'],1,0,'L',$fill);
			$this->Cell($w[3],7,$row['departname'],1,0,'L',$fill);
			$this->Cell($w[4],7,$row['cn_ip'],1,0,'L',$fill);
			$i++;

			$this->Ln();
			$fill=!$fill;
		}

		$this->Cell(array_sum($w),0,'','T');

		$this->Ln(3);
		
	}
}
$pdf=new PDF();
$header=array('No.','รหัสเครื่อง','ชื่อเครื่อง','แผนก/ฝ่าย','IP No.');

//*** Load MySQL Data ***//
include "../connect.php";
$strSQL = "SELECT  *  FROM comname LEFT  JOIN depart ON comname.de_id = depart.id
                                                         LEFT  JOIN computer ON comname.cn_id = computer.cn_id                                                      
                                                         LEFT  JOIN employee ON comname.emp_id = employee.emp_id
                                                         LEFT  JOIN userlog  ON comname.id_member = userlog.id_member
                                                         LEFT  JOIN product_detail ON comname.cn_number =  product_detail.pd_id 
                                                         ORDER BY c_refNumber ASC ";
$objQuery = mysql_query($strSQL);
mysql_query("set NAMES'TIS620'");
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
	$result = mysql_fetch_array($objQuery);

	$result['departname'] = iconv("UTF-8", "ISO-8859-11",$result['departname']);
          $result['cn_comeName'] = iconv("UTF-8", "ISO-8859-11",$result['cn_comeName']);
	array_push($resultData,$result);

}
//************************//
$pdf->AddPage('P','A4');
$pdf->AliasNbPages( 'tp' );
$pdf->FancyTable($header,$resultData);

$pdf->Output();
?>